import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter);
// 解决路由重复点击报异常问题
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject);
  return originalPush.call(this, location).catch(err => err);
};

const routes = [
  {
    path: '/',
    name: 'root',
    // component: Home,
    redirect:'login',
  },
  {
    path: '/login',
    name: 'login',
    component: () => import(/* webpackChunkName: "login" */ '../views/login.vue')
  },
  {
    path: "/home",
    name: "home",
    component: () => import(/* webpackChunkName: "home" */ "../components/layout/layout.vue"),
    redirect:'welcome',
    children:[
      {
        path: "/welcome",
        name: "welcome",
        component: () => import(/* webpackChunkName: "welcome" */ "../views/welcome.vue"),
        meta: {
          title: "欢迎页"
        }
      },
      {
        path: "/list",
        name: "list",
        component: () => import(/* webpackChunkName: "list" */ "../views/list.vue"),
        meta: {
          title: "列表页"
        }
      },
      {
        path: "/dataLook",
        name: "dataLook",
        component: () => import(/* webpackChunkName: "dataLook" */ "../views/dataLook.vue"),
        meta: {
          title: "数据预览"
        }
      },
      {
        path: "/monitor",
        name: "monitor",
        component: () => import(/* webpackChunkName: "monitor" */ "../views/monitor.vue"),
        meta: {
          title: "监控"
        }
      }
    ]
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
